package game.view.component
{
	import game.view.base.component.SystemNoticeUI;
	import com.base.type.LayerEnum;
	import com.base.view.ZooLayer;
	import com.greensock.TweenMax;
	public class SystemNotice extends SystemNoticeUI
	{
		private static var _instance:SystemNotice;
		
		public static function get instance():SystemNotice
		{
			if (_instance==null)_instance = new SystemNotice();
			return _instance;
		}
		
		public function SystemNoticeView()
		{
			super();
		}
		
		public function update(text:String,time:int=0):void
		{
			noticeLabel.text = text;
			showOrHide(true);
			//
			if (time>0) 
			{
				timeCountDown(time);
			}
		}
		
		private function timeCountDown(countdown:int=0):void
		{
			clear();
			if (countdown<0)
			{
				hide();
			}
			else
			{
				TweenMax.delayedCall(1,timeCountDown,[--countdown]);
			}
		}
		
		public function hide():void
		{
			clear();
			showOrHide(false);
		}
		
		private function clear():void
		{
			TweenMax.killDelayedCallsTo(timeCountDown);
		}
		
		private function showOrHide(value:Boolean):void
		{
			var layer:ZooLayer = ZooMain.view.getLayerByName(LayerEnum.LAYER_TOP);
			if (value) 
			{
				layer.addChild(this);
			}
			else if(layer.contains(this))
			{
				layer.removeChild(this);
			}
		}
	}
}